package com.onpositive.knowledge.model.values;

import java.util.ArrayList;

import com.onpositive.semantic.model.api.property.IFunction;
import com.onpositive.semantic.model.api.property.IProperty;

public class SimpleValueTransformer implements IValueTransformer{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6890605363979769997L;
	public static final String ID = "simple-value-transformer";
	final IFunction function;
	
	public SimpleValueTransformer(IFunction function) {
		super();
		this.function = function;
	}

	@Override
	public DescribedValue[] adjust(Object object, IProperty prop,
			DescribedValue... original) {
		ArrayList<DescribedValue>rs=new ArrayList<DescribedValue>();
		if (original!=null){
			for (DescribedValue o:original){
				Object value = function.getValue(o.value);
				DescribedValue describedValue = new DescribedValue(o.inferred, value,o.source, o.getComment() );
				rs.add(describedValue);
			}
		}		
		return rs.toArray(new DescribedValue[rs.size()]);
	}

	@Override
	public String getId() {
		return ID;
	}

}
